package com.report.word;

import com.deepoove.poi.render.compute.EnvModel;
import com.deepoove.poi.render.compute.RenderDataCompute;
import com.deepoove.poi.render.compute.RenderDataComputeFactory;
import org.springframework.expression.EvaluationContext;

import java.util.Map;

public class CustomRenderFactory implements RenderDataComputeFactory {

    private CustomRenderDataCompute compute = null;

    public CustomRenderFactory(Map<String, Object> root) {
        this.compute = new CustomRenderDataCompute(EnvModel.ofModel(root));
    }

    @Override
    public RenderDataCompute newCompute(EnvModel model) {
        Object target = model.getRoot();
        Map<String, Object> root = this.compute.getRootObject();
        if (target != root) {
            EvaluationContext context = this.compute.getEvaluationContext();
            context.setVariable("self", target);
        } else {
            EvaluationContext context = this.compute.getEvaluationContext();
            context.setVariable("self", null);
        }
        return compute;
    }

}
